package micotime.com.amap_plugin.map;

import android.content.Context;

import java.util.HashMap;
import java.util.Map;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;
import micotime.com.amap_plugin.map.model.UnifiedAMapOptions;

public class AMapViewFactory extends PlatformViewFactory {

    private final BinaryMessenger messenger;

    public AMapViewFactory(BinaryMessenger messenger) {
        super(StandardMessageCodec.INSTANCE);
        this.messenger = messenger;
    }

    @SuppressWarnings("unchecked")
    @Override
    public PlatformView create(Context context, int i, Object o) {
        try{
            Map<String, Object> params = null;
            if(o instanceof  HashMap){
                params = (HashMap<String, Object>) o;
            }
            AMapView aMapView = new AMapView(context, this.messenger, i, UnifiedAMapOptions.createWithMap(params));
            return aMapView;
        }catch( Exception e){
            throw e;
        }
    }
}
